package com.winsdom.controller;

import com.winsdom.annotation.OperationLog;
import com.winsdom.dto.threeTables.ThreeTablesDto;
import com.winsdom.entity.ThreeTables;
import com.winsdom.result.Result;
import com.winsdom.service.IThreeTablesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/threeTables")
@Api(tags = "三表管理相关接口")
public class ThreeTablesManageController {

    @Autowired
    private IThreeTablesService threeTablesService;

    @GetMapping("/nodes/resource")
    @ApiOperation("获取当前账号下已授权的楼盘的资源信息")
    @OperationLog(description = "获取当前账号下已授权的楼盘的资源信息")
    public Result getResourceTree() {
        Result result=threeTablesService.getResourceTree();
        return result;
    }

    @PostMapping("/getList")
    @ApiOperation("获取三表列表")
    @OperationLog(description = "获取三表列表")
    public Result getList(@RequestBody ThreeTablesDto threeTablesDto){
        return threeTablesService.getList(threeTablesDto);
    }

    @PostMapping("/add")
    @ApiOperation("添加三表")
    @OperationLog(description = "添加三表")
    public Result add(@RequestBody ThreeTables threeTables){
        return threeTablesService.add(threeTables);
    }

    @PostMapping("/update")
    @ApiOperation("修改三表")
    @OperationLog(description = "修改三表")
    public Result update(@RequestBody ThreeTables threeTables){
        return threeTablesService.updateThreeTables(threeTables);
    }

    @GetMapping("/delete/{id}")
    @ApiOperation("删除三表")
    @OperationLog(description = "删除三表")
    public Result delete(@PathVariable("id") Integer id){
        return threeTablesService.delete(id);
    }

    @GetMapping("/QRcode/{id}")
    @ApiOperation("获取二维码")
    @OperationLog(description = "获取二维码")
    public Result getQRcode(@PathVariable("id") Integer id) throws IOException {
        return threeTablesService.getQRcode(id);
    }


    @GetMapping("/get/batch/QRcode")
    @ApiOperation("批量获取二维码")
    @OperationLog(description = "批量获取二维码")
    public Result getBatchQRcode(@RequestParam("ids") List<Integer> ids) throws IOException {
        Result  result = threeTablesService.getBatchQRcode(ids);
        return result;
    }
}
